package cn.hd01.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.hd01.repository.entity.KValueDetail;
import cn.hd01.service.RebateSummaryService;
import cn.hd01.web.auth.Auth;

@Controller
@RequestMapping("/rebateSummary")
@Auth
public class RebateSummaryController {
	
	@Autowired
	private RebateSummaryService rebateSummaryService;
	
	@RequestMapping(method = RequestMethod.GET)
	public String index(Model m, HttpServletRequest request) {
		return "rebateSummary";
	}

	@ResponseBody
	@RequestMapping(path = "/list", method = RequestMethod.GET)
	private Page<KValueDetail> find(KValueDetail kValue, @PageableDefault Pageable pageable, HttpServletRequest req) {
		Sort sort = new Sort(Direction.DESC, "allRebate");
		PageRequest pageRequest = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), sort);
		return rebateSummaryService.findAll(kValue, pageRequest); 
	}
	
}
